/*
 * @Author: cl
 * @Description:
 * @Date: 2023-04-27 14:58:46
 * @LastEditTime: 2023-04-27 16:45:16
 * @FilePath: \jsnode\typescript\minix.ts
 * @LastEditors: cl
 */
// Disposable Mixin
// class Disposable {
//   isDisposed: boolean;
//   dispose() {
//       this.isDisposed = true;
//   }

// }

// // Activatable Mixin
// class Activatable {
//   isActive: boolean;
//   activate() {
//       this.isActive = true;
//   }
//   deactivate() {
//       this.isActive = false;
//   }
// }

// class SmartObject implements Disposable, Activatable {
//   constructor() {
//       setInterval(() => console.log(this.isActive + " : " + this.isDisposed), 500);
//   }

//   interact() {
//       this.activate();
//   }

//   // Disposable
//   isDisposed: boolean = false;
//   dispose: () => void;
//   // Activatable
//   isActive: boolean = false;
//   activate: () => void;
//   deactivate: () => void;
// }
// applyMixins(SmartObject, [Disposable, Activatable]);

// let smartObj = new SmartObject();
// setTimeout(() => smartObj.interact(), 1000);


////////////////////////////////////////
// In your runtime library somewhere
////////////////////////////////////////

function applyMixins(derivedCtor: any, baseCtors: any[]) {
  baseCtors.forEach(baseCtor => {
      Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
          derivedCtor.prototype[name] = baseCtor.prototype[name];
      });
  });
}

class AAA{
  name:string ='aName'
  say():void{
    console.log('say AAA');
  }
}
class BBB{
  age:string ='bAge'
  do():void{
    console.log('do BBB');
  }
}

class CCC implements AAA,BBB{
  age: string = 'cAge';
  do(): void {
    console.log('do CCC');
  }
  name: string = 'cName';
  say(): void {
    console.log('say CCC');
  }
}

class DDD extends AAA implements BBB{
  age: string= 'dAge';
  do(): void {
    console.log('do DDD');
  }
  say(): void {
    super.say()
    console.log('say DDD');
  }
}

applyMixins(CCC,[AAA,BBB])
let ccc = new CCC()
ccc.say()
ccc.do()
console.log(ccc);
let ddd = new DDD()
ddd.say()
ddd.do()
console.log(ddd);
